package cn.topevery.garden.dal.dao.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.topevery.garden.dal.dao.PlanCountDao;
import cn.topevery.garden.entity.po.PlanCount;
import cn.topevery.garden.entity.query.PlanCountQuery;
import cn.topevery.garden.entity.vo.PlanCountVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author code-generate
 * @date 2022-02-23
 */
@Repository
public class PlanCountDaoImpl extends BaseDaoImpl<PlanCount> implements PlanCountDao {
    @Override
    public <P extends DbCsp> List<PlanCount> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<PlanCountVO> listPage(PlanCountQuery query) {
        String table = "t_plan_count tpc";

        String columns = "tpc.*";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tpc.c_id desc");
        sqlQueryMate
                .where(true, "tpc.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(ObjectUtil.isNotEmpty(query.beginDate)&&ObjectUtil.isNotEmpty(query.endDate), "tpc.c_db_create_date", ScriptConditionEnum.GreaterThanEq, query.beginDate)
                .where(ObjectUtil.isNotEmpty(query.beginDate)&&ObjectUtil.isNotEmpty(query.endDate), "tpc.c_db_create_date", ScriptConditionEnum.LessThanEq, query.endDate)
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, PlanCountVO.class);
    }

    @Override
    public PlanCount getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }

    public Map<String, Object> getCountList(String name) {
        return getOneMap("SELECT tp.c_section_id sectionId,tp.c_section_name sectionName,sum(t.c_use_pay) val FROM t_schedule t JOIN t_plan tp ON t.c_schedule_id = tp.c_plan_id where tp.c_name='"+name+"' GROUP BY tp.c_section_name,tp.c_section_id ");
    }
}
